package com.lzm.ydpt.mvp.presenterimpl;

import com.byt.framlib.basemvp.BasePresenter;
import com.byt.framlib.basemvp.basebean.BaseResponseBean;
import com.byt.framlib.basemvp.basebean.ListPageBean;
import com.byt.framlib.basemvp.boby.FormBodys;
import com.byt.framlib.basemvp.exception.ApiException;
import com.byt.framlib.basemvp.listener.OnLoadingErrorListener;
import com.byt.framlib.basemvp.listener.OnLoadingProgressListener;
import com.lzm.ydpt.entity.mall.ProductBean;
import com.lzm.ydpt.entity.mall.ShopGoods;
import com.lzm.ydpt.module.mall.fragment.MallCartFragment;
import com.lzm.ydpt.mvp.api.ProgressSubscriber;
import com.lzm.ydpt.mvp.contract.MallCartContract;
import com.lzm.ydpt.mvp.modelimpl.MallCartModelImpl;

import java.util.List;

/**
 * 类名称：XhXnHelpPresenterImpl
 * 类描述：代理实现
 */
public class MallCartPresenterImpl extends BasePresenter implements MallCartContract.Presenter {

    private MallCartContract.View mView;
    private MallCartContract.Model mModel;

    public MallCartPresenterImpl(MallCartFragment context) {
        super(context.getActivity());
        this.mView = context;
        this.mModel = new MallCartModelImpl();
    }

    @Override
    public void onProductCartList(FormBodys formBodys) {
        mManager.http(mModel.onProductCartList(formBodys), getLifecycleProvider(), new ProgressSubscriber<>(mContext, new OnLoadingProgressListener<ListPageBean<ShopGoods>>() {
            @Override
            public void onLoadingResult(BaseResponseBean<ListPageBean<ShopGoods>> entity) {
                mView.onProductCartList(entity.getData());
            }
        }, new OnLoadingErrorListener() {
            @Override
            public void onError(ApiException e, String method) {
                mView.showErrorView(e.getDisplayMessage());
            }

            @Override
            public void onErrorResult(BaseResponseBean entity, String method) {
                mView.showErrorView(entity.getMessage());
            }
        }, "onProductCartList"));
    }

    @Override
    public void onDeteleProductCart(FormBodys formBodys, List<ShopGoods> tempList) {
        mManager.http(mModel.onDeteleProductCart(formBodys), getLifecycleProvider(), new ProgressSubscriber<>(mContext, new OnLoadingProgressListener<Object>() {
            @Override
            public void onLoadingResult(BaseResponseBean<Object> entity) {
                mView.onDeteleProductCart(entity.getMessage(), tempList);
            }
        }, new OnLoadingErrorListener() {
            @Override
            public void onError(ApiException e, String method) {
                mView.showMessage(e.getDisplayMessage(), method);
            }

            @Override
            public void onErrorResult(BaseResponseBean entity, String method) {
                mView.showMessage(entity.getMessage(), method);
            }
        }, "onDeteleProductCart"));
    }

    @Override
    public void onShoppingCart(FormBodys formBodys, int position, int num) {
        mManager.http(mModel.onShoppingCart(formBodys), getLifecycleProvider(), new ProgressSubscriber<>(mContext, new OnLoadingProgressListener<Object>() {
            @Override
            public void onLoadingResult(BaseResponseBean<Object> entity) {
                mView.onShoppingCart(entity.getMessage(), position, num);
            }
        }, new OnLoadingErrorListener() {
            @Override
            public void onError(ApiException e, String method) {
                mView.showMessage(e.getDisplayMessage(), method);
            }

            @Override
            public void onErrorResult(BaseResponseBean entity, String method) {
                mView.showMessage(entity.getMessage(), method);
            }
        }, "onShoppingCart"));
    }

    @Override
    public void onShopGuessLike(FormBodys formBodys) {
        mManager.http(mModel.onShopGuessLike(formBodys), getLifecycleProvider(), new ProgressSubscriber<>(mContext, new OnLoadingProgressListener<ListPageBean<ProductBean>>() {
            @Override
            public void onLoadingResult(BaseResponseBean<ListPageBean<ProductBean>> entity) {
                mView.onShopGuessLike(entity.getData());
            }
        }, new OnLoadingErrorListener() {
            @Override
            public void onError(ApiException e, String method) {
                mView.showMessage(e.getDisplayMessage(), method);
            }

            @Override
            public void onErrorResult(BaseResponseBean entity, String method) {
                mView.showMessage(entity.getMessage(), method);
            }
        }, "onShopGuessLike"));
    }
}